const db = require("../utils/db");

// 路由-拼接菜单
exports.menuGet = async (params) => {
    return new Promise(((resolve, reject) => {
        let sql = '',selectContent='';
        for(let item of params){
            selectContent += ` or secondmenu.sm_id = ${item}`
        }
        selectContent = selectContent.slice(3);
        console.log(selectContent);
        sql = `select * from firstmenu,secondmenu where secondmenu.sm_firstid=firstmenu.fm_id and (${selectContent})`;
        console.log(sql,'sql');

        db.query(sql).then(res => {
            console.log(res, "menuGet sql查询成功结果")

            resolve(res);
        }).catch(error => {
            console.log(error, "menuGet sql查询失败结果")
            reject(error)

        })
    }))
}

// 路由-获取二级菜单列表
exports.menuListGet = async (params) => {
    return new Promise(((resolve, reject) => {
        let sql = `select * from secondmenu `;
        db.query(sql).then(res => {
            console.log(res, "menuGet sql查询成功结果")
            resolve(res);
        }).catch(error => {
            console.log(error, "menuGet sql查询失败结果")
            reject(error)

        })
    }))
}
